//
//  StatusCellBottomView.swift
//  weibo
//
//  Created by apple on 15/12/20.
//  Copyright © 2015年 LYR. All rights reserved.
//

import UIKit

class StatusCellBottomView: UIView {
    
    // 评论按钮的点击事件
    @objc private func commentDidClick() {
    
       let temp = TempViewController()
    
       self.navController()?.pushViewController(temp, animated: true)
    
    }
    
    //MARK:定义外部模型属性
    
    
    //MARK:重写构造方法
    override init(frame: CGRect) {
        
        super.init(frame: frame)
        
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    //MARK:设置页面 布局
    private func setupUI() {
        
        addSubview(retweetedBtn)
        addSubview(commentBtn)
        addSubview(likeBtn)
        
        //  得到两个view 用来设置分割线
        let sepView1 = sepView()
        let sepView2 = sepView()
        let w: CGFloat = 0.5
        let scale: CGFloat = 0.4
        
        //   添加分割线view
        addSubview(sepView1)
        addSubview(sepView2)
        
        //  添加转发按钮的约束
        retweetedBtn.snp_makeConstraints { (make) -> Void in
            make.left.top.bottom.equalTo(self)
            
        }
        //  添加评论按钮的约束
        commentBtn.snp_makeConstraints { (make) -> Void in
            make.top.bottom.equalTo(self)
            make.left.equalTo(retweetedBtn.snp_right)
            make.width.equalTo(retweetedBtn.snp_width)
        }
        
        //  添加点赞按钮的约束
        likeBtn.snp_makeConstraints { (make) -> Void in
            make.right.equalTo(self.snp_right)
            make.left.equalTo(commentBtn.snp_right)
            make.width.equalTo(commentBtn.snp_width)
            make.top.bottom.equalTo(self)
        }
        
        //  设置分割线view的约束
        sepView1.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(retweetedBtn.snp_right)
            make.centerY.equalTo(self.snp_centerY)
            make.height.equalTo(self.snp_height).multipliedBy(scale)
            make.width.equalTo(w)
        }
        
        sepView2.snp_makeConstraints { (make) -> Void in
            make.right.equalTo(likeBtn.snp_left)
//            make.left.equalTo(commentBtn.snp_right)
            make.centerY.equalTo(self.snp_centerY)
            make.height.equalTo(self.snp_height).multipliedBy(scale)
            make.width.equalTo(w)
        }
        
        //  评论按钮的点击事件
        commentBtn.addTarget(self, action: "commentDidClick", forControlEvents: .TouchUpInside)
        
        
    }
    
    // 生成分割线
    private func sepView() -> UIView {
        let v = UIView()
         v.backgroundColor = UIColor.darkGrayColor()
         return v
    }
    
    
    
    
    // MARK:懒加载所有的子视图
    //  转发
    private lazy var retweetedBtn: UIButton = UIButton(title: "转发", imageName: "timeline_icon_retweet", backImageName: nil, fontSize: 10, color: UIColor.darkGrayColor())
    //  评论
    private lazy var commentBtn: UIButton = UIButton(title: "评论", imageName: "timeline_icon_comment", backImageName: nil, fontSize: 10, color: UIColor.darkGrayColor())
    //  点赞
    private lazy var likeBtn: UIButton = UIButton(title: "赞", imageName: "timeline_icon_unlike", backImageName: nil, fontSize: 10, color: UIColor.darkGrayColor())
    
}
